
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 12/04/2014 14:25:21
-- Generated from EDMX file: D:\Projects\SMIC\CityDashboard\CityDashboard.Service\CityDashboardModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [CityDashboard];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[View_DA_Capmoi_2014_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[View_DA_Capmoi_2014_HPT];
GO
IF OBJECT_ID(N'[dbo].[View_DA_giaithe_2014_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[View_DA_giaithe_2014_HPT];
GO
IF OBJECT_ID(N'[dbo].[View_DonViCapPhep_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[View_DonViCapPhep_HPT];
GO
IF OBJECT_ID(N'[dbo].[View_HSDangGiaiQuyet_Detail_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[View_HSDangGiaiQuyet_Detail_HPT];
GO
IF OBJECT_ID(N'[dbo].[View_LoaiHS_trinhUB_DungHan_Detail_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[View_LoaiHS_trinhUB_DungHan_Detail_HPT];
GO
IF OBJECT_ID(N'[dbo].[View_LoaiHS_trinhUB_DungHan_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[View_LoaiHS_trinhUB_DungHan_HPT];
GO
IF OBJECT_ID(N'[dbo].[view_top5DA_by_vondautuUSD_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[view_top5DA_by_vondautuUSD_HPT];
GO
IF OBJECT_ID(N'[dbo].[ViewDADT_byloaiDN_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ViewDADT_byloaiDN_HPT];
GO
IF OBJECT_ID(N'[dbo].[ViewDADT_byTenloaiHinhDT_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ViewDADT_byTenloaiHinhDT_HPT];
GO
IF OBJECT_ID(N'[dbo].[ViewDADT_byTenloaiHinhDT_USD_HPT]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ViewDADT_byTenloaiHinhDT_USD_HPT];
GO
IF OBJECT_ID(N'[CityDashboardModelStoreContainer].[sp_ThongTinTrangXuLy]', 'U') IS NOT NULL
    DROP TABLE [CityDashboardModelStoreContainer].[sp_ThongTinTrangXuLy];
GO
IF OBJECT_ID(N'[CityDashboardModelStoreContainer].[View_HSDangGiaiQuyet_HPT]', 'U') IS NOT NULL
    DROP TABLE [CityDashboardModelStoreContainer].[View_HSDangGiaiQuyet_HPT];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'View_DA_Capmoi_2014_HPT'
CREATE TABLE [dbo].[View_DA_Capmoi_2014_HPT] (
    [So_DA] int  NOT NULL,
    [tongvonUSD] decimal(38,6)  NULL
);
GO

-- Creating table 'View_DA_giaithe_2014_HPT'
CREATE TABLE [dbo].[View_DA_giaithe_2014_HPT] (
    [So_DA] int  NOT NULL,
    [tongvonUSD] decimal(38,6)  NULL
);
GO

-- Creating table 'View_DonViCapPhep_HPT'
CREATE TABLE [dbo].[View_DonViCapPhep_HPT] (
    [khu] int  NOT NULL,
    [khu_desc] varchar(5)  NOT NULL,
    [so_DA] int  NULL,
    [tongvonUSD] decimal(38,6)  NULL
);
GO

-- Creating table 'View_HSDangGiaiQuyet_Detail_HPT'
CREATE TABLE [dbo].[View_HSDangGiaiQuyet_Detail_HPT] (
    [type] int  NOT NULL,
    [Sobnhan] varchar(20)  NOT NULL,
    [trangthai_hs] nvarchar(21)  NOT NULL,
    [type_ttrang] int  NOT NULL,
    [xuly] nvarchar(15)  NOT NULL,
    [TenDN] nvarchar(1000)  NULL,
    [TenDuAn] nvarchar(1000)  NULL,
    [NgayNhan] datetime  NOT NULL,
    [ngayhtra] datetime  NULL
);
GO

-- Creating table 'View_LoaiHS_trinhUB_DungHan_Detail_HPT'
CREATE TABLE [dbo].[View_LoaiHS_trinhUB_DungHan_Detail_HPT] (
    [sobnhan] varchar(20)  NOT NULL,
    [trinhUBND] int  NOT NULL,
    [trinhUBND_desc] nvarchar(19)  NOT NULL,
    [loai_hs] int  NOT NULL,
    [loai_hs_desc] nvarchar(18)  NOT NULL,
    [dung_han] int  NOT NULL,
    [dung_han_desc] nvarchar(8)  NOT NULL,
    [TenDN] nvarchar(1000)  NULL,
    [TenDuAn] nvarchar(1000)  NULL,
    [NgayNhan] datetime  NOT NULL,
    [ngayhtra] datetime  NULL
);
GO

-- Creating table 'View_LoaiHS_trinhUB_DungHan_HPT'
CREATE TABLE [dbo].[View_LoaiHS_trinhUB_DungHan_HPT] (
    [loai_hs] int  NOT NULL,
    [loai_hs_desc] nvarchar(18)  NOT NULL,
    [trinhUBND] int  NOT NULL,
    [trinhUBND_desc] nvarchar(19)  NOT NULL,
    [TT_DungHan] int  NOT NULL,
    [TT_DungHan_desc] nvarchar(8)  NOT NULL,
    [soluong] int  NULL
);
GO

-- Creating table 'view_top5DA_by_vondautuUSD_HPT'
CREATE TABLE [dbo].[view_top5DA_by_vondautuUSD_HPT] (
    [socndautu] varchar(20)  NOT NULL,
    [TenDuAnDautu] nvarchar(500)  NOT NULL,
    [TongvonUSD] decimal(38,6)  NULL
);
GO

-- Creating table 'ViewDADT_byloaiDN_HPT'
CREATE TABLE [dbo].[ViewDADT_byloaiDN_HPT] (
    [TenLoaiDN] nvarchar(100)  NOT NULL,
    [sl] int  NULL
);
GO

-- Creating table 'ViewDADT_byTenloaiHinhDT_HPT'
CREATE TABLE [dbo].[ViewDADT_byTenloaiHinhDT_HPT] (
    [TenloaiHinhDT] nvarchar(100)  NOT NULL,
    [sl] int  NULL
);
GO

-- Creating table 'ViewDADT_byTenloaiHinhDT_USD_HPT'
CREATE TABLE [dbo].[ViewDADT_byTenloaiHinhDT_USD_HPT] (
    [TenloaiHinhDT] nvarchar(100)  NOT NULL,
    [sl] decimal(38,6)  NULL
);
GO

-- Creating table 'sp_ThongTinTrangXuLy'
CREATE TABLE [dbo].[sp_ThongTinTrangXuLy] (
    [tentinhtrang] nvarchar(250)  NULL,
    [ngayxuly] datetime  NULL,
    [tenchuyenvien] nvarchar(200)  NULL,
    [SoBnhan] varchar(20)  NOT NULL
);
GO

-- Creating table 'View_HSDangGiaiQuyet_HPT'
CREATE TABLE [dbo].[View_HSDangGiaiQuyet_HPT] (
    [type] int  NOT NULL,
    [trangthai_hs] nvarchar(21)  NOT NULL,
    [type_ttrang] int  NOT NULL,
    [xuly] nvarchar(15)  NOT NULL,
    [soluong] int  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [So_DA] in table 'View_DA_Capmoi_2014_HPT'
ALTER TABLE [dbo].[View_DA_Capmoi_2014_HPT]
ADD CONSTRAINT [PK_View_DA_Capmoi_2014_HPT]
    PRIMARY KEY CLUSTERED ([So_DA] ASC);
GO

-- Creating primary key on [So_DA] in table 'View_DA_giaithe_2014_HPT'
ALTER TABLE [dbo].[View_DA_giaithe_2014_HPT]
ADD CONSTRAINT [PK_View_DA_giaithe_2014_HPT]
    PRIMARY KEY CLUSTERED ([So_DA] ASC);
GO

-- Creating primary key on [khu] in table 'View_DonViCapPhep_HPT'
ALTER TABLE [dbo].[View_DonViCapPhep_HPT]
ADD CONSTRAINT [PK_View_DonViCapPhep_HPT]
    PRIMARY KEY CLUSTERED ([khu] ASC);
GO

-- Creating primary key on [Sobnhan] in table 'View_HSDangGiaiQuyet_Detail_HPT'
ALTER TABLE [dbo].[View_HSDangGiaiQuyet_Detail_HPT]
ADD CONSTRAINT [PK_View_HSDangGiaiQuyet_Detail_HPT]
    PRIMARY KEY CLUSTERED ([Sobnhan] ASC);
GO

-- Creating primary key on [sobnhan], [trinhUBND], [loai_hs], [dung_han] in table 'View_LoaiHS_trinhUB_DungHan_Detail_HPT'
ALTER TABLE [dbo].[View_LoaiHS_trinhUB_DungHan_Detail_HPT]
ADD CONSTRAINT [PK_View_LoaiHS_trinhUB_DungHan_Detail_HPT]
    PRIMARY KEY CLUSTERED ([sobnhan], [trinhUBND], [loai_hs], [dung_han] ASC);
GO

-- Creating primary key on [loai_hs], [trinhUBND], [TT_DungHan] in table 'View_LoaiHS_trinhUB_DungHan_HPT'
ALTER TABLE [dbo].[View_LoaiHS_trinhUB_DungHan_HPT]
ADD CONSTRAINT [PK_View_LoaiHS_trinhUB_DungHan_HPT]
    PRIMARY KEY CLUSTERED ([loai_hs], [trinhUBND], [TT_DungHan] ASC);
GO

-- Creating primary key on [socndautu] in table 'view_top5DA_by_vondautuUSD_HPT'
ALTER TABLE [dbo].[view_top5DA_by_vondautuUSD_HPT]
ADD CONSTRAINT [PK_view_top5DA_by_vondautuUSD_HPT]
    PRIMARY KEY CLUSTERED ([socndautu] ASC);
GO

-- Creating primary key on [TenLoaiDN] in table 'ViewDADT_byloaiDN_HPT'
ALTER TABLE [dbo].[ViewDADT_byloaiDN_HPT]
ADD CONSTRAINT [PK_ViewDADT_byloaiDN_HPT]
    PRIMARY KEY CLUSTERED ([TenLoaiDN] ASC);
GO

-- Creating primary key on [TenloaiHinhDT] in table 'ViewDADT_byTenloaiHinhDT_HPT'
ALTER TABLE [dbo].[ViewDADT_byTenloaiHinhDT_HPT]
ADD CONSTRAINT [PK_ViewDADT_byTenloaiHinhDT_HPT]
    PRIMARY KEY CLUSTERED ([TenloaiHinhDT] ASC);
GO

-- Creating primary key on [TenloaiHinhDT] in table 'ViewDADT_byTenloaiHinhDT_USD_HPT'
ALTER TABLE [dbo].[ViewDADT_byTenloaiHinhDT_USD_HPT]
ADD CONSTRAINT [PK_ViewDADT_byTenloaiHinhDT_USD_HPT]
    PRIMARY KEY CLUSTERED ([TenloaiHinhDT] ASC);
GO

-- Creating primary key on [SoBnhan] in table 'sp_ThongTinTrangXuLy'
ALTER TABLE [dbo].[sp_ThongTinTrangXuLy]
ADD CONSTRAINT [PK_sp_ThongTinTrangXuLy]
    PRIMARY KEY CLUSTERED ([SoBnhan] ASC);
GO

-- Creating primary key on [type], [trangthai_hs], [type_ttrang], [xuly] in table 'View_HSDangGiaiQuyet_HPT'
ALTER TABLE [dbo].[View_HSDangGiaiQuyet_HPT]
ADD CONSTRAINT [PK_View_HSDangGiaiQuyet_HPT]
    PRIMARY KEY CLUSTERED ([type], [trangthai_hs], [type_ttrang], [xuly] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------